<%--
  Created by IntelliJ IDEA.
  User: LuoQuan
  Date: 2017/11/14
  Time: 15:38
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>SSE Demo</title>
</head>
<body>
<div id="msgFrompPush"></div>
<script type="text/javascript" src="<c:url value="assets/js/jquery.js"/>"></script>
<script type="text/javascript">
    if (!!window.EventSource) {
        var source = new EventSource('push');

        source.onmessage = function (e) {
            $("#msgFrompPush").append(e.data + "<br/>");
        };
        /*source.addEventListener('message', function (e) {
            $("#msgFrompPush").append(e.data + "<br/>");
        });*/

        source.addEventListener('open', function (e) {
            console.log('连接打开');
        }, false);

        source.addEventListener('error', function (e) {
            if (source.readyState === EventSource.CLOSED) {
                console.log('连接关闭');
            } else {
                console.log(source.readyState);
            }
        }, false);
    } else {
        console.log('你的浏览器不支持SSE');
    }
</script>
</body>
</html>
